﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

/// <reference name="MicrosoftAjax.js" />

Type.registerNamespace("Microsoft.Live.ClientControls.VE.Extenders") ; 
Microsoft.Live.ClientControls.VE.Extenders.Clear = function(element) {
    /// <summary>
    ///   The Microsoft Live Server Controls VE Map Clear Extender client side code.
    /// </summary>
    /// <param name="element">The DOM element to have Clear event on click.</param>
    Microsoft.Live.ClientControls.VE.Extenders.Clear.initializeBase(this, [element]) ; 

    this._mapControlID;
} 

Microsoft.Live.ClientControls.VE.Extenders.Clear.prototype = {

    initialize : function() {
        /// <summary>
        ///   Initialises the Extender.
        /// </summary>       
        Microsoft.Live.ClientControls.VE.Extenders.Clear.callBaseMethod(this, 'initialize');
        
        $addHandler(this.get_element(),"click", Function.createDelegate(this, this._onClick));
    }, 
    
    get_MapControlID : function() {
        return this._mapControlID;
    }, 

    set_MapControlID : function(value) {
        this._mapControlID = value;
    },        
    
    _onClick : function(e) {
        //Get the map control and Clear
        var mapcontrol = $find(this._mapControlID);
        if (mapcontrol) {
            mapcontrol.Clear();
        }
        //Don't want the page to post back, so prevent default action of control
        e.preventDefault();
    },
    
    dispose : function() {
        /// <summary>
        ///   Dispose all events and objects.
        /// </summary>     
        $clearHandlers(this.get_element());
        Microsoft.Live.ClientControls.VE.Extenders.Clear.callBaseMethod(this, 'dispose');
    }
} 

Microsoft.Live.ClientControls.VE.Extenders.Clear.registerClass("Microsoft.Live.ClientControls.VE.Extenders.Clear", Sys.UI.Behavior) ;

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();